package approve.adapter;

import java.util.ArrayList;

import model.pojo.Employee;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import approve.action.App_ViewForm12;
import approve.action.App_ViewForm13;
import approve.action.App_ViewForm14;
import approve.action.App_ViewForm15;
import approve.action.App_ViewForm16;
import approve.action.App_ViewForm17;
import approve.action.App_ViewForm_LessThan10;
import approve.action.R;

public class ListEmployeeReferAdapter  extends BaseAdapter{

	Context context;
	ArrayList<Employee> emlist= new ArrayList<Employee>();
	String strid;
	int flagviewcontext;
	ViewHolder holder;
	public ListEmployeeReferAdapter(){
		
	}
	public ListEmployeeReferAdapter(App_ViewForm_LessThan10 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	public ListEmployeeReferAdapter(App_ViewForm12 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	public ListEmployeeReferAdapter(App_ViewForm13 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	public ListEmployeeReferAdapter(App_ViewForm14 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	public ListEmployeeReferAdapter(App_ViewForm15 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	public ListEmployeeReferAdapter(App_ViewForm16 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	public ListEmployeeReferAdapter(App_ViewForm17 context,ArrayList<Employee> emlist, int flag){
		super();
		this.emlist=emlist;
		this.context=context;
		this.flagviewcontext=flag;
	}
	
	@Override
	public int getCount() {
		return emlist.size();
	}
	@Override
	public Object getItem(int position) {
		return emlist.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Employee em = emlist.get(position);
		
		if(convertView==null){
			holder = new ViewHolder();
			
			LayoutInflater a=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = a.inflate(R.layout.listemployeereferadapter, parent,false);
			
			holder.imi_deleterefer = (ImageView)convertView.findViewById(R.id.imi_deleterefer);
			holder.textname = (TextView) convertView.findViewById(R.id.check);
			
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		
		holder.textname.setText(em.getFullName());
				
		holder.imi_deleterefer.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				em.setChecked(false);
				emlist.remove(em);
				
				if(flagviewcontext==10){
					((App_ViewForm_LessThan10)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm_LessThan10)context).getApproverlist();
					((App_ViewForm_LessThan10)context).getChooseapproveradapter().notifyDataSetChanged();
				}else if(flagviewcontext==12){
					((App_ViewForm12)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm12)context).getApproverlist();
					((App_ViewForm12)context).getChooseapproveradapter().notifyDataSetChanged();
				}else if(flagviewcontext==13){
					((App_ViewForm13)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm13)context).getApproverlist();
					((App_ViewForm13)context).getChooseapproveradapter().notifyDataSetChanged();
				}else if(flagviewcontext==14){
					((App_ViewForm14)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm14)context).getApproverlist();
					((App_ViewForm14)context).getChooseapproveradapter().notifyDataSetChanged();
				}else if(flagviewcontext==15){
					((App_ViewForm15)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm15)context).getApproverlist();
					((App_ViewForm15)context).getChooseapproveradapter().notifyDataSetChanged();
				}else if(flagviewcontext==16){
					((App_ViewForm16)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm16)context).getApproverlist();
					((App_ViewForm16)context).getChooseapproveradapter().notifyDataSetChanged();
				}else if(flagviewcontext==17){
					((App_ViewForm17)context).getChooseapproveradapter().getListCheckRefer().remove(em);
					((App_ViewForm17)context).getApproverlist();
					((App_ViewForm17)context).getChooseapproveradapter().notifyDataSetChanged();
				}
				
			}
		});
		return convertView;
	}
	public ArrayList<Employee> getEmlist() {
		return emlist;
	}
	public void setEmlist(ArrayList<Employee> emlist) {
		this.emlist = emlist;
	}
	public Context getContext() {
		return context;
	}
	public void setContext(Context context) {
		this.context = context;
	}
	public String getStrid() {
		strid="";
		if(emlist.size()>0){
			for(int i=0;i<emlist.size();i++){
				if(strid.equals("")){
					strid="'"+emlist.get(i).getIdemployee()+"'";
				}else{
					strid+=",'"+emlist.get(i).getIdemployee()+"'";
				}
			}
		}
		return strid;
	}
	public void setStrid(String strid) {
		this.strid = strid;
	}
	
	public static class ViewHolder{
		 ImageView imi_deleterefer;
		 TextView textname;
	}
}
